package cn.chencaiju.day08;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

public class WordCount {
	public void wordCount(String str) {
		String[] strs=str.split("[ .\"\"]");
		Map<String,Integer> mapCount=new HashMap<>();
		for(String temp:strs) {
			if(mapCount.get(temp)==null) {
				mapCount.put(temp, 1);
				continue;
			}
			mapCount.put(temp, mapCount.get(temp)+1);
		}
		Set<Entry<String, Integer>> entrySet = mapCount.entrySet();
		for(Entry<String, Integer> item:entrySet) {
			System.out.println(item.getKey()+"\t\t"+item.getValue());
		}
		
	}
	@Test public void testWordCount() {
		StringBuilder sb=new StringBuilder( "The passing years steal from us one thing after another.");
		sb.append("The man who has made up his mind to win will never say \"impossible\".");
		System.out.println(sb.toString());
		wordCount(sb.toString());
	}
}
